<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
	</style>
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">
		<script type="text/html" id="platform_toolbar">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加平台 </button>
			</div>
		</script>

		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

		<script type="text/html" id="currentTableBar">
			<a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">修改</a>
		</script>
		<script type="text/html" id="switchTpl">
  			<!-- 这里的 checked 的状态只是演示 -->
  			<input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="sexDemo" {{ d.status == 1 ? 'checked' : '' }}>
		</script>

	</div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
//添加
function get_add(){
	layer.open({
        type: 2,
        title:'添加平台信息',
        area: ['50%', '50%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('add_platform')}" 
    });
    //layer.full(index);
}
//修改
function get_save(id){
	layer.open({
        type: 2,
        title:'修改平台信息',
        area: ['50%', '50%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('save_platform')}?id="+id 
    });
    //layer.full(index);
}
var $,form,table;
	layui.use(['form', 'table', 'laydate'], function () {
		$ = layui.jquery
			, form = layui.form
			, table = layui.table
			;

		table.render({
			elem: '#currentTableId',
			height: 'full-150',
			id:'testReload',
			url: '{:url("platform")}?t=json',
			method : 'post',
			toolbar: '#platform_toolbar',
			cols: [[
				{ type: 'numbers', title: '编号',  },
				{ field: 'name', title: '平台名称',  },
				{ field: 'proj_num', align: 'center', title: '在投/总计',  },
				{ field: 'yesterday_recharge', align: 'right', title: '昨日充值', sort: true },
				{ field: 'total_recharge', align: 'right', title: '充值总计',  sort: true },
				{ field: 'consumed', align: 'right', title: '昨日消耗',  sort: true },
				{ field: 'total_consumed', align: 'right', title: '消耗总计',  sort: true },
				{ field : 'status', title : '平台状态' ,templet: '#switchTpl', unresize: true},
				{ field: 'create_time', title: '创建时间' },
				{ field: 'note', title: '备注' },
				{ title: '操作', fixed: 'right', toolbar: '#currentTableBar', align: "center" }
			]],
			limit: 30,
			page: true,
			skin: 'line',
			even: true
		});
		/**
		 * toolbar监听事件
		 */
		table.on('toolbar(currentTableFilter)', function (obj) {
			switch (obj.event) {
				case 'add':
					get_add();
				break;
			}
			
		});

		//监听操作栏事件
		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'edit':
					get_save(data.id)
				break;
			}
			
		});
		//监听开关操作
		form.on('switch(sexDemo)', function(obj){
		    //layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
		    var x = obj.elem.checked;
		    var id = this.value;
		    layer.confirm('您确认要修改平台即子渠道状态吗？', {
		    	  btn: ['确认','取消'] //按钮
		    	}, function(){
		    		get_save_platform_status(obj,id,x)
		    	});
		    obj.elem.checked=!x;
          	form.render();
		  });

	});
	//修改平台状态
	function get_save_platform_status(obj,id,status){
		sta = status?'1':"0";
		layer.load(1, {shade: [0.5,'#676a6c']}); 
		$.post("{:url('get_save_platform_status')}?t=json",{id:id,status:sta},function(data){
			layer.closeAll();
			if(data.code == 1){
				layer.msg(data['msg'], {icon: 6});
				obj.elem.checked=status;
	            form.render();
			}else{
				layer.msg(data['msg'], {icon: 5});
			}
			
		});
	}
	
	//重载数据表
	function get_s(msg){
		table.reload('testReload', {
			  url: '{:url("platform")}?t=json',
			});
		layer.msg(msg, {icon: 6});
	}
</script>

</body>
</html>